export function formatUTC (utcDateString) {
  const date = new Date(utcDateString)
  const options = {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
    timeZone: 'Asia/Shanghai',
    hour12: false // 将小时显示为24小时制
  }
  return date.toLocaleString('zh-CN', options).replace(/\//g, '-') // 将斜杠替换为短横线
}
export function getNight (date1, date2) {
  // 检查参数是否是有效的日期对象
  if (!(date1 instanceof Date && !isNaN(date1))) {
    throw new Error('Invalid date object: ' + date1)
  }

  if (!(date2 instanceof Date && !isNaN(date2))) {
    throw new Error('Invalid date object: ' + date2)
  }
  const diffTime = date2.getTime() - date1.getTime()
  const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))

  let nights = 0
  if (diffDays === 1 && date1.getHours() >= 18) {
    nights = 1
  } else if (diffDays > 1 || (diffDays === 1 && (date1.getHours() >= 18 || date2.getHours() < 6))) {
    const start = new Date(date1)
    start.setHours(18, 0, 0, 0)
    const end = new Date(date2)
    end.setHours(6, 0, 0, 0)
    const diffTime = end.getTime() - start.getTime()
    const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))
    nights = diffDays
  }

  return nights
}
